package com.tool.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.swing.SwingConstants;

import com.gl.util.Xy2Util;
import com.tool.image.ImageMixDeal;
import com.tool.role.Ql;
import com.updateNew.MyIsif;
import org.come.Frame.*;
import org.come.Jpanel.*;
import org.come.action.petpaixu.PetpxJpanel;
import org.come.bean.AllPet;
import org.come.bean.SuitOperBean;
import org.come.entity.Pal;
import org.come.entity.PartJade;
import org.come.entity.RoleSummoning;
import org.come.model.PalData;
import org.come.mouslisten.*;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import com.tool.PanelDisplay.PetPanelShow;
import com.tool.imagemonitor.FightingMonitor;
import com.tool.pet.PetProperty;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;

import come.tool.Fighting.FightingMixDeal;
import come.tool.Fighting.Fightingimage;
import come.tool.Fighting.TypeState;
import come.tool.JDialog.TiShiUtil;
import come.tool.handle.HandleState;

/**
 * 召唤兽面板按钮
 *
 * @author Administrator
 */
public class PetPanelBtn extends MoBanBtn {
    private TestPetJpanel jpanel;
    //    private HuaLianJpanel huaLianJpanel;//葫芦娃
    private HuaLianJpanel huaLianJpanel;
    private SyntheticGourdDollJpanel syntheticGourdDollJpanel;//葫芦娃
    /**
     * 1是改名 2是参战 3休息 4加点 5驯养 6技能 7物品 8炼妖 9 放生 10抗性 11 召唤
     */
    private Integer typeBtn;

    public PetPanelBtn(String iconpath, int type, Integer typeBtn, TestPetJpanel jpanel) {
        // TODO Auto-generated constructor stub
        super(iconpath, type);
        // this.setText(text);
        this.typeBtn = typeBtn;

        setFont(UIUtils.TEXT_FONT1);
        setForeground(Color.yellow);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.jpanel = jpanel;
    }

    public PetPanelBtn(String iconpath, int type, Color[] colors, Font font, String text, Integer typeBtn, TestPetJpanel jpanel) {
        // TODO Auto-generated constructor stub
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        this.typeBtn = typeBtn;
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.jpanel = jpanel;
    }

    public PetPanelBtn(String iconpath, int type, Color[] colors, Font font, String text, Integer typeBtn, HuaLianJpanel huaLianJpanel) {//葫芦娃
        // TODO Auto-generated constructor stub
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        this.typeBtn = typeBtn;
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.huaLianJpanel = huaLianJpanel;
    }

    public PetPanelBtn(String iconpath, int type, Color[] colors, Font font, String text, Integer typeBtn, SyntheticGourdDollJpanel syntheticGourdDollJpanel) {//葫芦娃
        // TODO Auto-generated constructor stub
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        this.typeBtn = typeBtn;
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.syntheticGourdDollJpanel = syntheticGourdDollJpanel;
    }


    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        if (ImageMixDeal.userimg.getRoleShow().getBooth_id() != null) {
            ZhuFrame.getZhuJpanel().addPrompt2("摆摊状态不可以操作！");
            return;
        }
        if (UserMessUntil.getChosePetMes() == null && typeBtn != 23) {
            ZhuFrame.getZhuJpanel().addPrompt2("您还没有选中召唤兽呢!!");
            return;
        }
        // TODO Auto-generated method stub
        if (typeBtn == 1 && FightingMixDeal.State == HandleState.USUAL) {
            changname();
        } else if (typeBtn == 2 && FightingMixDeal.State == HandleState.USUAL) {
            canzhan();
        } else if (typeBtn == 3 && FightingMixDeal.State == HandleState.USUAL) {
            try {
                xiuxi();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        } else if (typeBtn == 4 && FightingMixDeal.State == HandleState.USUAL) {
            try {
                jiadian();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        } else if (typeBtn == 5 && FightingMixDeal.State == HandleState.USUAL) {
            xunyang();
        } else if (typeBtn == 6) {

            ChosePetSkillsMouslisten.refreshPetSkills();
            // 展示技能面板
            FormsManagement.showForm(18);
        } else if (typeBtn == 601) {
            ChosePetLxMouslisten.refreshPetSkills();
            // 展示灵犀面板
            FormsManagement.showForm(601);
        } else if (typeBtn == 7 && FightingMixDeal.State == HandleState.USUAL) {
            ZhuJpanel.setUseGoodsType(1);
            PetEquipmentJframe.getPetEquipmentJframe().getEquipmentJpanel().showPet(UserMessUntil.getChosePetMes());
            FormsManagement.HideForm(2);
            FormsManagement.upgradForm(67);
            PetEquipmentJpanel.starRating = UserMessUntil.getChosePetMes().getFragment();//召唤兽升星
        } else if (typeBtn == 8 && FightingMixDeal.State == HandleState.USUAL) {
            lianyao();
        } else if (typeBtn == 9 && FightingMixDeal.State == HandleState.USUAL) {
            /**判断是否解锁*/
            if (Util.isCanBuyOrno()) {
                return;
            }
            if (UserMessUntil.getChosePetMes() == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("没有选中的召唤兽");
                return;
            }
            OptionsJframe.getOptionsJframe().getOptionsJpanel().
                    showBox(TiShiUtil.Release, UserMessUntil.getChosePetMes(), "#W确定要将召唤兽:#G" + UserMessUntil.getChosePetMes().getSummoningname() + "#W放生吗?");
        } else if (typeBtn == 10) {
            petZhanshi();
        } else if (typeBtn.intValue() == 15) {//葫芦娃
            // 化莲
            RoleSummoning pet = huaLianJpanel.getPet();
            Integer grade = pet.getGrade();
            if (grade < 221) {
                ZhuFrame.getZhuJpanel().addPrompt2("等级不够");
                return;
            }
            Long qm = pet.getFriendliness();
            if (qm < 200000) {
                ZhuFrame.getZhuJpanel().addPrompt2("亲密不够");
                return;
            }
            OptionsJframe.getOptionsJframe().getOptionsJpanel().
                    showBox(TiShiUtil.huaLian, UserMessUntil.getChosePetMes(), "#W进行化莲后，葫芦娃将变为七色花瓣，你确定要化莲吗？");
        } else if (typeBtn.intValue() == 16) {
            if (UserMessUntil.getPetListTable() != null && UserMessUntil.getPetListTable().size() >= RoleData.getRoleData().getPackRecord().getPettNum()) {
                ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽可携带的数量已满！！！");
                return;
            }
            Integer[] goodsIndexs = syntheticGourdDollJpanel.getGoodsIndexs();
            List<Integer> indexs = Arrays.asList(goodsIndexs);
            if (indexs.size() < 7) {
                ZhuFrame.getZhuJpanel().addPrompt2("物品不足！！！");
                return;
            }
            SuitOperBean operBean = new SuitOperBean();
            operBean.setType(21);
            operBean.setJade(new PartJade(1, 761));
            operBean.setGoods(GoodsListFromServerUntil.Delete2(indexs));
            String senmes = Agreement.suitOperateAgreement(GsonUtil.getGsonUtil().getgson().toJson(operBean));
            SendMessageUntil.toServer(senmes);
            FormsManagement.HideForm(702);
        } else if (typeBtn == 100) {
            // 召唤兽幻肤面板
            huanfu();
        } else if (typeBtn == 20) {//宠物跟随
            changePet(true);
        } else if (typeBtn == 17 && FightingMixDeal.State == 0) {
            if (Util.isCanBuyOrno()) {
            } else {
                if (UserMessUntil.getChosePetMes() == null) {
                    ZhuFrame.getZhuJpanel().addPrompt2("没有选中的召唤兽");
                } else {
                    OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.Decompose, UserMessUntil.getChosePetMes(), "#W确定要将召唤兽:#G" + UserMessUntil.getChosePetMes().getSummoningname() + "#W分解吗?"
                            + "#Y分解后可以获得#R召唤兽碎片，#Y集齐碎片可以用于唤兽#R升星#Y;");
                }
            }
        } else if (typeBtn == 21) {//跟随隐藏
            changePet(false);
        } else if ("排".equals(this.getText())) {
            if (!FormsManagement.getframe(1117).isVisible()) {

                FormsManagement.showForm(1117);
                PetpxJpanel.showStar();
            } else {
                FormsManagement.HideForm(1117);
            }
        } else if (typeBtn == 21) {//跟随隐藏
            changePet(false);
        } else if (typeBtn == 24) {//寄存
            RoleSummoning roleSummoning = UserMessUntil.getChosePetMes();
            if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null && RoleData.getRoleData().getLoginResult().getSummoning_id().compareTo(roleSummoning.getSid()) == 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽已在参战中！无法寄存！");
                return;
            }

            String mes = Agreement.getAgreement().petDepositAction("deposit=" + roleSummoning.getSid());
            // 向服务器发送信息
            SendMessageUntil.toServer(mes);
            UserMessUntil.setChosePetMes(null);
//            changePet(true);
        } else if (typeBtn == 23) {//取回
//            changePet(false);
            RoleData roleData = RoleData.getRoleData();
            DepositListJframe.getDepositListJframe().getDepositListJpanel().init(roleData.getDepositBbName());
            FormsManagement.showForm(63333);
        } else if (FightingMixDeal.State == HandleState.HANDLE_PLAYER && typeBtn == 11) {
            Fightingimage fightingimage = FightingMixDeal.getdata(0);
            List<TypeState> data = fightingimage.getFightingManData().cxxx("召唤兽");
            int sid = UserMessUntil.getChosePetMes().getSid().intValue();
            for (int i = 0; i < data.size(); i++) {
                if (data.get(i).getState() != 0) {
                    continue;
                }
                if (sid == Integer.parseInt(data.get(i).getType())) {
                    if (FightingMixDeal.State != HandleState.HANDLE_PLAYER) {
                        return;
                    }
                    FormsManagement.HideForm(6);
                    // 生成召唤指令
                    FightingMonitor.FightingOperation(FightingBtn.SpellGenerate("召唤&" + data.get(i).getType()));
                    FightingMonitor.operateEnd();
                    return;
                }
            }
            ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽无法召唤");

        } else if (typeBtn == 22) {
            RoleData roleData = RoleData.getRoleData();
            roleData.addHelpBb(roleData.getHelpBbId());
            PXSupportListJframe.getPXSupportListJframe().getPXSupportListJpanel().initS(roleData.getHelpBbName(roleData.getHelpBb()));
            FormsManagement.showForm(620);
        } else if (typeBtn == 110 && FightingMixDeal.State == HandleState.USUAL) {//
            /**判断是否解锁*/
            if (Util.isCanBuyOrno()) {
                return;
            }
            if (UserMessUntil.getChosePetMes() == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("没有选中的召唤兽");
                return;
            }
            RoleSummoning pet = UserMessUntil.getChosePetMes();
            PartnerMainJpanel mainJpanel = PartnerJframe.getPartnerJframe().getPartnerMainJpanel();
            if (mainJpanel.getPalDataChooseId() < 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选择一个伙伴");
                return;
            }
            Pal pidGetPal = mainJpanel.pidGetPal(mainJpanel.getPalDataChooseId());
            if (pidGetPal == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选中一个伙伴");
                return;
            }
            int TurnRount = AnalysisString.petTurnRount(pet.getGrade());
            if (TurnRount < 1) {
                ZhuFrame.getZhuJpanel().addPrompt2("宝宝一转以后才可以分配给召唤兽哦！");
                return;
            }
            PalData palData = UserMessUntil.getPalData(pidGetPal.getpId());
            String name = palData.getName();
            if (pidGetPal.getSummoning() != null) {
                ZhuFrame.getZhuJpanel().addPrompt2("伙伴【#G" + name + "#Y】已有召唤兽，请先取回");
                return;
            }
            OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.palAddPet, pet, "#W确定要将召唤兽:#G" + pet.getSummoningname() + "#W分配到伙伴:【#G" + name + "#W】吗?");
        } else if (typeBtn == 111) {
            FormsManagement.showForm(3019);
        } else if (typeBtn == 112) {// 炼魂
            RoleSummoning pet = UserMessUntil.getChosePetMes();
            if (Util.isCanBuyOrno()) {
                return;
            }
            if (UserMessUntil.getChosePetMes() == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("没有选中的召唤兽");
                return;
            }
            if (pet.getPetlock() == 1) {
                ZhuFrame.getZhuJpanel().addPrompt("该召唤兽已加锁，不能炼魂。。");
                return;
            }

            if (pet.getGoods() != null) {
                ZhuFrame.getZhuJpanel().addPrompt("该召唤兽携带着装备");
                return;
            }

            if (ZhuJpanel.getPetMount(pet.getSid()) != null) {
                ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽被管制中，不可炼魂！！！");
                return;
            }

            if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null && RoleData.getRoleData().getLoginResult().getSummoning_id().compareTo(pet.getSid()) == 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽已在参战中！！！");
                return;
            }
            OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.lianhunPet, pet, "#W确定要将召唤兽#R" + pet.getSummoningname() + "#W炼魂吗？#W#Y炼魂#W后不可恢复！");
        } else if (typeBtn == 113) {// 聚魄
            if (Util.isCanBuyOrno()) {
                return;
            }
            if (UserMessUntil.getChosePetMes() == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("没有选中的召唤兽");
                return;
            }
            RoleSummoning pet = UserMessUntil.getChosePetMes();
            if (pet.getPetlock() == 1) {
                ZhuFrame.getZhuJpanel().addPrompt("该召唤兽已加锁，不能聚魄。。");
                return;
            }

            if (pet.getGoods() != null) {
                ZhuFrame.getZhuJpanel().addPrompt("该召唤兽携带着装备");
                return;
            }

            if (ZhuJpanel.getPetMount(pet.getSid()) != null) {
                ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽被管制中，不可聚魄！！！");
                return;
            }

            if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null && RoleData.getRoleData().getLoginResult().getSummoning_id().compareTo(pet.getSid()) == 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("这只召唤兽已在参战中！！！");
                return;
            }
            OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.jupoPet, pet, "#W确定要将召唤兽#R" + pet.getSummoningname() + "#W聚魄吗？#W#Y聚魄#W后不可恢复！");
//            #W此功能为#R一键回收#W，会将#Y当前打开的物品栏#W中的非加锁且可回收物品全部回收，你确定要这么操作吗? #R（注意，物品回收后不可找回！
        } else if (typeBtn == 114) {//
            Xy2Util.addpetList = new ArrayList<>();
            AllPet allpet = UserMessUntil.getAllPet();
            Map<BigDecimal, RoleSummoning> allMap = allpet.getRoleSummoningHashMap();
            for (BigDecimal key : allMap.keySet()) {
                Xy2Util.addpetList.add(allMap.get(key));
            }
            // 展示图鉴面板
            FormsManagement.showForm(3013);
        }
    }

    /**
     * 改名
     */
    public void changname() {
        // 将更改的名字进行传送到服务器进行修改数据
        try {
            if (UserMessUntil.getChosePetMes() != null) {
                String lastname = UserMessUntil.getChosePetMes().getSummoningname();
                // 若要修改的名字为空，则提示其输入新的召唤兽名字
                if (TestPetJpanel.getLabname().getText() == null || "".equals(TestPetJpanel.getLabname().getText())) {

                    ZhuFrame.getZhuJpanel().addPrompt("请输入召唤兽" + lastname + "的新名字！");
                    return;
                }
                if (TestPetJpanel.getLabname().getText().length() > 9) {
                    ZhuFrame.getZhuJpanel().addPrompt("长?那是一种专属");
                    return;
                }
                // 改变名字
                UserMessUntil.getChosePetMes().setSummoningname(TestPetJpanel.getLabname().getText().trim());


                // 发送给服务器
                String mes = Agreement.getAgreement().petchangeAgreement(GsonUtil.getGsonUtil().getgson().toJson(UserMessUntil.getChosePetMes()));
                // 向服务器发送信息
                SendMessageUntil.toServer(mes);
                ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽改名为:" + UserMessUntil.getChosePetMes().getSummoningname());
                // 刷新面板

                TestPetJpanel.showStar();
            } else {
                ZhuFrame.getZhuJpanel().addPrompt("请选择你要改名的召唤兽！");
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

    /**
     * 参战
     */
    public void canzhan() {
        // 将宠物头像框设置为有头像
        String path = "img/newHead/p" + UserMessUntil.getChosePetMes().getSummoningskin() + ".png";
        ZhuJpanel.setLabpetimg(path);
//        ZhuJpanel.setLabpetimg(UserMessUntil.getChosePetMes().getSummoningskin(),1);
        // 选中的召唤兽id
        String mes = Agreement.getAgreement().rolechangeAgreement("P" + UserMessUntil.getChosePetMes().getSid().toString());
        SendMessageUntil.toServer(mes);
        // 设置自身携带的宠物id
        RoleData.getRoleData().getLoginResult().setSummoning_id(UserMessUntil.getChosePetMes().getSid());
        // 绘制召唤兽 3条
        Article.souxie(UserMessUntil.getChosePetMes());
        PetPanelShow.ShowMesForJpanel();
        jpanel.getBtnwar().setText("休息");
        if ("水墨UI".equals(MyIsif.getStyle())) {
            jpanel.getBtnwar().setColors(UIUtils.COLOR_BLACK);
        } else {
            jpanel.getBtnwar().setColors(UIUtils.COLOR_BTNPUTONG2);
        }

        jpanel.getBtnwar().setTypeBtn(3);
        TestPetJpanel.showStar();
    }

    /**
     * 休息
     */
    public void xiuxi() throws Exception {
        ZhuJpanel.setLabpetimg(null);
        String mes = Agreement.getAgreement().rolechangeAgreement("P");
        SendMessageUntil.toServer(mes);
        RoleData.getRoleData().getLoginResult().setSummoning_id(null);
        jpanel.getBtnwar().setText("参战");
        if ("水墨UI".equals(MyIsif.getStyle())) {
            jpanel.getBtnwar().setColors(UIUtils.COLOR_BLACK);
        } else {
            jpanel.getBtnwar().setColors(UIUtils.COLOR_BTNPUTONG2);
        }

        jpanel.getBtnwar().setTypeBtn(2);
        TestPetJpanel.showStar();
    }

    /**
     * 加点
     */
    public void jiadian() throws Exception {
        RoleSummoning pet = UserMessUntil.getChosePetMes();
        int Jbone = Integer.valueOf(TestPetJpanel.getLabrootbone().getText());
        int JSpir = Integer.valueOf(TestPetJpanel.getLabintelligence().getText());
        int JPower = Integer.valueOf(TestPetJpanel.getLabpower().getText());
        int JSpeed = Integer.valueOf(TestPetJpanel.getLabspeed().getText());
        int JCalm = Integer.valueOf(TestPetJpanel.getLabconcentrate().getText());
        int canpoint = pet.getCanpoint();
        canpoint -= Jbone;
        canpoint -= JSpir;
        canpoint -= JPower;
        canpoint -= JSpeed;
        canpoint -= JCalm;

        canpoint += pet.getZBone();
        canpoint += pet.getZSpir();
        canpoint += pet.getZPower();
        canpoint += pet.getZSpeed();
        canpoint += pet.getZCalm();
        if (canpoint >= 0
                && (Jbone > pet.getZBone() || JSpir > pet.getZSpir() || JPower > pet.getZPower()
                || JSpeed > pet.getZSpeed() || JCalm > pet.getZCalm())) {
            // 设置根骨数目
            pet.setZBone(Jbone);
            // 设置最新灵性
            pet.setZSpir(JSpir);
            // 设置最新力量
            pet.setZPower(JPower);
            // 设置敏捷度
            pet.setZSpeed(JSpeed);
            // 设置定力
            pet.setZCalm(JCalm);
            // 增加对应的属性
            PetAddPointMouslisten.showPetValue();
//            pet.setLyk("忽视防御几率=299|忽视防御程度=299|无属性伤害=199|命中=199|抗水=199|抗火=199|抗雷=199|抗风=199|致命=299|反击率=100|命中率=100|抗封印=199|抗昏睡=199|抗混乱=199|抗遗忘=199|抗鬼火=199|狂暴率=299|致命率=299|连击率=100|忽视反击=100|昏睡躲闪=199|混乱躲闪=199|封印躲闪=199|附加三尸攻击=100|伤害减免=199|反击次数=30|附加毒法攻击=199|附加混乱攻击=199|附加震慑攻击=100|附加水法攻击=199|附加雷法攻击=199|忽视抗水=299|忽视抗雷=299|水法伤害=999999|水法狂暴几率=199|雷法伤害=999999|雷法狂暴几率=199|忽视躲闪=199|物理吸收=199|忽视抗震慑=199|物理伤害=999999|加强毒伤害=999999|连击次数=30|土=100|木=100|水=100|火=100|金=100|");
            // 发送给服务器
            String mes = Agreement.getAgreement().petchangeAgreement(GsonUtil.getGsonUtil().getgson().toJson(pet));
            // 向服务器发送信息
            SendMessageUntil.toServer(mes);
        }
    }

    /**
     * 驯养
     */
    public void xunyang() {
        // 选中了召唤兽，然后把宠物口粮进行解析
        int a = 0;
        for (int i = 0; i < GoodsListFromServerUntil.getGoodslist().length; i++) {
            if (UserMessUntil.getChosePetMes().getFaithful() >= 100) {
                ZhuFrame.getZhuJpanel().addPrompt2(
                        "召唤兽 " + UserMessUntil.getChosePetMes().getSummoningname() + "的忠诚度已满！！！");
                return;
            }
            if (GoodsListFromServerUntil.getGoodslist()[i] != null
                    && GoodsListFromServerUntil.getGoodslist()[i].getType() == 49) {
                UserMessUntil.getChosePetMes().addFaithful(
                        Integer.parseInt(GoodsListFromServerUntil.getGoodslist()[i].getValue()));
                ZhuFrame.getZhuJpanel().addPrompt2(
                        "召唤兽 " + UserMessUntil.getChosePetMes().getSummoningname() + "增加了"
                                + GoodsListFromServerUntil.getGoodslist()[i].getValue() + "点忠诚度啦！！！");
                GoodsListFromServerUntil.getGoodslist()[i].goodxh(1);
                GoodsMouslisten.gooduse(GoodsListFromServerUntil.getGoodslist()[i], 1);
                if (GoodsListFromServerUntil.getGoodslist()[i].getUsetime() <= 0) {
                    GoodsListFromServerUntil.Deleted(i);
                }
                // 将这个召唤兽发给服务器
                SendRoleAndRolesummingUntil.sendRoleSumming(UserMessUntil.getChosePetMes());
                // 刷新界面忠诚度
                TestPetJpanel.getLabloyalty().setText(UserMessUntil.getChosePetMes().getFaithful().toString());
                a = 1;
            }
        }
        if (a == 0) {
            ZhuFrame.getZhuJpanel().addPrompt2("您没有足够宠物口粮了！！！");
        }
    }

    /**
     * 炼妖
     */
    public void lianyao() {
        // 清空左上角放置召唤兽的表格
        AlchemyJframe.getAlchemyjframe().getalchemyJpanel().getListModel().removeAllElements();
        // 将自己的召唤兽列表放到界面上
        if (UserMessUntil.getPetListTable() != null) {
            for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
                AlchemyJframe.getAlchemyjframe().getalchemyJpanel().getListModel().add(i, UserMessUntil.getPetListTable().get(i).getSummoningname());
            }
        }
        // 将界面展示出来
        FormsManagement.upgradForm(17);

    }

    /**
     * 召唤兽抗性面板展示
     */
    public void petZhanshi() {
        if (UserMessUntil.getChosePetMes() == null) {
            // 显示在聊天面板
            FrameMessageChangeJpanel.addtext(5, "请选择你要查看抗性的召唤兽！", null, null);
        } else {
            // 展示召唤兽抗性面板
            if (!FormsManagement.getframe(58).isVisible()) {
                PetProperty.ShowQl(UserMessUntil.getChosePetMes());
                FormsManagement.showForm(58);
            } else {
                FormsManagement.HideForm(58);
            }

        }
    }

    public static List<String> parseXy(String input) {
        List<String> numbers = new ArrayList<>();

        if (input == null) {
            return new ArrayList<>();
        }
        // 分割字符串
        String[] parts = input.split("#");


        // 找到 Y 后面的数字并存入列表
        for (int i = 1; i < parts.length - 1; i++) {
            String current = parts[i];
            numbers.add(current);
        }

        return numbers;
    }

    /**
     * 进行遍历展示召唤兽抗性
     */
    public static void showRolesumming(Object model) {
        int a = -1, doub = -1, jishu = -1;
        try {
            clearShuXingView();
            RoleSummoning chosePetMes = UserMessUntil.getChosePetMes();
            if (chosePetMes == null) {
                return;
            }
            if ("727".equals(chosePetMes.getSummoningskin())) {
                Ql ql = (Ql) model;
                List<String> strings = parseXy(chosePetMes.getXy());
                for (String string : strings) {
                    if ("2".equals(string)) {
                        ql.setRolefzml(ql.getRolefzml() + 6);
                    } else if ("10".equals(string)) {
                        ql.setRolehsfyv(ql.getRolehsfyv() + 10);
                    } else if ("9".equals(string)) {
                        ql.setRolehsfyl(ql.getRolehsfyl() + 10);
                    } else if ("8".equals(string)) {
                        ql.setRolefljl(ql.getRolefljl() + 6);
                    }
                }
            }
            for (java.lang.reflect.Field field : model.getClass().getDeclaredFields()) {
                field.setAccessible(true);
                if (Double.parseDouble(field.get(model).toString()) != 0) {
                    String sx = null;
                    sx = JpanelOnJalbelBtn.getQuaralyPersonalName(field.getName());
                    // //system.out.println("值： " + sx);
                    String ping = GoodsMsgJpanel.tianjia(sx);
                    String numbers = sx.substring(sx.length() - 1, sx.length());
                    Integer number = Integer.valueOf(numbers);
                    // Integer number = Integer.valueOf(1);
                    String shuxingName = sx.substring(0, sx.length() - 2);
                    a++;
                    if (a % 2 == 0) {
                        doub++;
                        RolePetResistanceJframe.getResistancejframe().getResistancejpanel();
                        if ("%".equals(ping)) {
                            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[number - 1]
                                    .getDlm().addElement(
                                            shuxingName
                                                    + ":"
                                                    + String.format("%.1f",
                                                    Double.parseDouble(field.get(model).toString())) + ping);
                        } else {
                            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[number - 1]
                                    .getDlm().addElement(
                                            shuxingName + ":" + (int) Double.parseDouble(field.get(model).toString())
                                                    + ping);
                        }
                    } else {
                        jishu++;
                        RolePetResistanceJframe.getResistancejframe().getResistancejpanel();
                        if ("%".equals(ping)) {
                            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[number - 1]
                                    .getDlm1().addElement(
                                            shuxingName
                                                    + ":"
                                                    + String.format("%.1f",
                                                    Double.parseDouble(field.get(model).toString())) + ping);
                        } else {
                            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[number - 1]
                                    .getDlm1().addElement(
                                            shuxingName + ":" + (int) Double.parseDouble(field.get(model).toString())
                                                    + ping);
                        }
                    }
                }
            }
            changViewSize();
        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * 更新抗性面板大小
     */
    public static void changViewSize() {
        if ("水墨UI".equals(MyIsif.getStyle())) {
            for (int i = 0; i < RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel().length; i++) {
                int leftNum = RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i]
                        .getDlm().getSize();
                int rightNum = RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i]
                        .getDlm1().getSize();
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getListNo1()
                        .setBounds(20, 26, 130, leftNum * 17);
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getListNo2()
                        .setBounds(150, 26, 130, rightNum * 17);
                int num = leftNum > rightNum ? leftNum : rightNum;
                num = num > 0 ? (num * 17 + 34) : 24;
                int y = 0;
                for (int j = 0; j < i; j++) {
                    y += RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[j]
                            .getHeight();
                }
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].setBounds(0, y,
                        300, num);
            }
            int y = 0;
            for (int i = 0; i < RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel().length; i++) {
                y += RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getHeight();
            }
            // RoleResistanceJframe.getResistancejframe().getResistancejpanel().setBounds(RoleResistanceJframe.getResistancejframe().getResistancejpanel().getX(),RoleResistanceJframe.getResistancejframe().getResistancejpanel().getY(),290,y);
            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().setSize(300, y);
            RolePetResistanceJframe.getResistancejframe().setSize(300, y);
        } else {
            for (int i = 0; i < RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel().length; i++) {
                int leftNum = RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i]
                        .getDlm().getSize();
                int rightNum = RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i]
                        .getDlm1().getSize();
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getListNo1()
                        .setBounds(20, 26, 130, leftNum * 17);
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getListNo2()
                        .setBounds(150, 26, 130, rightNum * 17);
                int num = leftNum > rightNum ? leftNum : rightNum;
                num = num > 0 ? (num * 17 + 34) : 24;
                int y = 0;
                for (int j = 0; j < i; j++) {
                    y += RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[j]
                            .getHeight();
                }
                RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].setBounds(0, y,
                        290, num);
            }
            int y = 0;
            for (int i = 0; i < RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel().length; i++) {
                y += RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getHeight();
            }
            // RoleResistanceJframe.getResistancejframe().getResistancejpanel().setBounds(RoleResistanceJframe.getResistancejframe().getResistancejpanel().getX(),RoleResistanceJframe.getResistancejframe().getResistancejpanel().getY(),290,y);
            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().setSize(290, y);
            RolePetResistanceJframe.getResistancejframe().setSize(290, y);
        }
    }

    /**
     * 清空抗性面板内容
     */
    public static void clearShuXingView() {
        for (int i = 0; i < RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel().length; i++) {
            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getDlm().removeAllElements();
            RolePetResistanceJframe.getResistancejframe().getResistancejpanel().getShuXingJpanel()[i].getDlm1().removeAllElements();
        }
    }

    private void changePet(boolean b) {

        if (b && RoleData.getRoleData().getLoginResult().getSummoning_id() != null && RoleData.getRoleData().getLoginResult().getSummoning_id().compareTo(UserMessUntil.getChosePetMes().getSid()) == 0) {
            ZhuFrame.getZhuJpanel().addPrompt2("参战召唤兽不可以观看！");
            return;
        }


        // 宠物跟随 观看独立数据，解决召唤兽加点，吃内丹，加血加法，人物自动停止任务
        // 改变名字
        UserMessUntil.getChosePetMes().setShow(b);
        // 发送给服务器
        String mes = Agreement.getAgreement().petchangeAgreement(
                GsonUtil.getGsonUtil().getgson().toJson(UserMessUntil.getChosePetMes()));
        // 向服务器发送信息
        SendMessageUntil.toServer(mes);
        // 刷新面板
        TestPetJpanel.showStar();
        // 宠物跟随 观看独立数据，解决召唤兽加点，吃内丹，加血加法，人物自动停止任务
    }

    public Integer getTypeBtn() {
        return typeBtn;
    }

    public void setTypeBtn(Integer typeBtn) {
        this.typeBtn = typeBtn;
    }

    public void huanfu() {
        // 清空左上角放置召唤兽的表格
        ZhshuanfutujianJframe.getZhshuanfutujianJframe().getZhshuanfutujianJpanel().getListModel().removeAllElements();
        // 将自己的召唤兽列表放到界面上
        if (UserMessUntil.getPetListTable() != null) {
            for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
                ZhshuanfutujianJframe.getZhshuanfutujianJframe().getZhshuanfutujianJpanel().getListModel().add(i, UserMessUntil.getPetListTable().get(i).getSummoningname());
            }
        }
        // 将界面展示出来
        FormsManagement.upgradForm(607);


    }
}
